const ArticleModel  =require('../../public/Model')
//管理员获取文章列表
const adminGetArticle = async(req,res)=>{
   const result =  await ArticleModel.findAll()
   if(result){
    res.send({
        code:200,
        message:'获取文章列表成功',
        data:result
    })
   }
}
//管理员拉取oss文章并写入本地数据库(类似于发布新的文章)
const adminSendArticle =async(req,res)=>{

}
//管理员下架某一篇文章
const adminDownLineArticle = async(req,res)=>{
    const result  =  await ArticleModel.update({
        status:'delete'
    },{
        where:{
            id:req.query.id
        }
    })
    if(result){
        res.send({
            code:200,
            message:'文章已下线',
        })
    }
}
//管理员重新启用某一篇文章
const adminUpLineArticle =async(req,res)=>{
        const result  =  await ArticleModel.update({
        status:'publish'
    },{
        where:{
            id:req.query.id
        }
    })
    if(result){
        res.send({
            code:200,
            message:'文章已下线',
        })
    }
}
module.exports ={
    adminGetArticle,
    adminSendArticle,
    adminUpLineArticle,
   adminDownLineArticle,
}